package com.lzy.cloud.ticket.train.controller;

import com.lzy.cloud.ticket.train.dtos.TrainCodeDto;
import com.lzy.cloud.ticket.train.facade.StationFacade;
import com.lzy.cloud.ticket.train.facade.TimeTableFacade;
import com.lzy.cloud.ticket.train.request.app.TimeTableAppRequest;
import com.lzy.cloud.ticket.train.response.BaseResponse;
import com.lzy.cloud.ticket.train.response.TimeTableResponse;
import com.lzy.cloud.ticket.train.response.TrainCodeResponse;
import com.lzy.cloud.ticket.train.util.ErrorUtil;
import com.lzy.framework.core.ensure.Ensure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/station")
public class TrainStationController {

    @Autowired
    private StationFacade stationFacade;

    @Autowired
    private ErrorUtil errorUtil;

    @Autowired
    private TimeTableFacade timeTableFacade;

    /**
     * 获取站点简码
     *
     * @return
     */
    @RequestMapping(value = "/Mistiness",method = RequestMethod.GET)
    public BaseResponse queryStationList(@RequestParam String stationName){
        TrainCodeDto trainCodeDto = new TrainCodeDto();
        trainCodeDto.setStationName(stationName);
        TrainCodeResponse trainCodeResponse = stationFacade.queryStationCode(trainCodeDto);
        Ensure.that(trainCodeResponse).isNotNull("00010001");
        return trainCodeResponse;
    }

    /**
     * 获取站点
     *
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public BaseResponse queryStationList() {
        TrainCodeResponse trainCodeResponse = stationFacade.queryStationList();
        Ensure.that(trainCodeResponse).isNotNull("00010001");
        Ensure.that(errorUtil.toError(trainCodeResponse)).isTrue("00010001");
        return trainCodeResponse;
    }

    /**
     * 时刻表查询
     *
     * @return
     */
    @RequestMapping(value = "/time", method = RequestMethod.POST)
    public TimeTableResponse queryTimeTable(@RequestBody TimeTableAppRequest timeTableAppRequest) {
        TimeTableResponse timeTableResponse = timeTableFacade.queryTimeTable(timeTableAppRequest);
        Ensure.that(timeTableResponse).isNotNull("00010001");
        Ensure.that(errorUtil.toError(timeTableResponse)).isTrue("00010001");
        return timeTableResponse;
    }

}
